package com.xinchuang;

import org.gdal.gdal.gdal;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import javax.persistence.OrderBy;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

/**
 * TODO
 *
 * @author zkwczx
 * @version 1.0
 * @date 2023/9/22 11:20
 */
@Order(value = 1)
@Component
public class InitRunner implements ApplicationRunner {

    @Override
    public void run(ApplicationArguments args) throws Exception {
        trustAllHosts();
        gdal.AllRegister();
        gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
        gdal.SetConfigOption("SHAPE_ENCODING", "");
    }

    //分析与构建  结合一体
    //快速实现
    //体系构建
    //体系  小模块 体系包裹体系
    //参数  增加 地图范围的展示  配置  （多个圆圈的融合展示  （同一类型））

    private static void trustAllHosts() {
        // 创建信任管理器
        TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
            @Override
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return new java.security.cert.X509Certificate[]{};
            }
            @Override
            public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
            }
            @Override
            public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
            }
        }};
        try {
            SSLContext sc = SSLContext.getInstance("TLS");
            sc.init(null, trustAllCerts, new java.security.SecureRandom());
            HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
